﻿Public Class Pro4_3




    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim itm As String
        itm = InputBox("INGRESE NOMBRE DE NUEVA CIUDAD", " NUEVA CIUDAD")
        If itm <> "" Then addElemento(itm)

    End Sub
    Sub addElemento(ByVal newItem As String)
        Dim idx As Integer
        If Not ComboBox1.Items.Contains(newItem) Then
            idx = ComboBox1.Items.Add(newItem)
        Else
            idx = ComboBox1.Items.IndexOf(newItem)
        End If
        ComboBox1.SelectedIndex = idx

    End Sub

    Private Sub ComboBox1_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.LostFocus
        Dim newitem As String = ComboBox1.Text
        addElemento(newitem)

    End Sub

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox2.Items.AddRange(New String() {"PERU", "BOLIVIA", "ARGENTINA", "CHILE", "ECUADOR"})
        ComboBox1.Items.AddRange(New String() {"BUENOS AIRES", "TRUJILLO", "LIMA", "AREQUIPA", "SANTIAGO", "QUITO", "LA PAZ"})

        ComboBox1.Sorted = True
        ComboBox2.Sorted = True
        ComboBox1.SelectedItem = 6
        ComboBox2.SelectedItem = 4


    End Sub



    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Pro4_2.Show()
        Me.Visible = False




    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim itm As String
        itm = InputBox("INGRESE NOMBRE DE NUEVO PAIS", " NUEVO PAIS")
        If itm <> "" Then addElemento2(itm)
    End Sub
    Sub addElemento2(ByVal newItem As String)
        Dim idx As Integer
        If Not ComboBox1.Items.Contains(newItem) Then
            idx = ComboBox2.Items.Add(newItem)
        Else
            idx = ComboBox2.Items.IndexOf(newItem)
        End If
        ComboBox2.SelectedIndex = idx

    End Sub

    Private Sub ComboBox2_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.LostFocus
        Dim newitem As String = ComboBox2.Text
        addElemento2(newitem)

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Pro4_4.Show()
        Me.Visible = False


    End Sub
End Class